/*
 * spi.h
 *
 *  Created on: Sep 30, 2010
 *      Author: tron
 */

#ifndef SPI_H_
#define SPI_H_

#include <avr/io.h>
#include <inttypes.h>

#ifndef _SS
#define _SS	PB2
#endif
/*
 * When the DORD bit is written to one, the LSB of the data word is transmitted
 * first. Use DORDL when initializing SPI.
 * when the DORD bit is written to zero, the MSB of the data word is transmitted
 * first. Use DORDM when initializing SPI.
 */
#ifndef DORDL
#define DORDL	1
#endif
#ifndef DORDM
#define DORDM	0
#endif

/*
 * When the CPOL bit is written to one, SCK is high when idle. Use CPOLH when
 * initializing SPI.
 * when the CPOL bit is written to zero, SCK is held low when idle. Use CPOLL
 * when initializing SPI.
 */
#ifndef CPOLL
#define CPOLL	0
#endif
#ifndef CPOLH
#define CPOLH	1
#endif

#define spi_init_master(_dord,_cpol)	SPCR = (_BV(MSTR) | _BV(SPE)\
		| (_dord<<DORD) | (_cpol << CPOL));\
	DDRB |= _BV(_SS);

uint8_t spi_master_write(uint8_t byte);

#endif /* SPI_H_ */
